﻿/*
 * Created by SharpDevelop.
 * User: cszhangyi
 * Date: 2016/4/8
 * Time: 16:29
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

using Newtonsoft.Json;
using YMTSeller.Model;

namespace YMTSeller
{
	/// <summary>
	/// Description of ProductHandler.
	/// </summary>
	public class ProductHandler
	{
		YMTRequest request = new YMTRequest();
		
		private string accessToken = "";
		private string userId = "";
		
		public ProductHandler(string accessToken, string userid)
		{
			this.accessToken = accessToken;
			this.userId = userid;
		}
		
		public string addProduct(int activityId)
		{
			string url = "http://seller.app.ymatou.com/api/Product/AddProductV2";
			
			var model = new AddProductRequestModel();
			
			model.ActivityIds = new List<int>();
			model.DescriptionModelPicList = new List<string>();
			model.DescriptionModelText = new List<string>();
			model.ProductPics = new List<string>();
			
			
			model.AccessToken = this.accessToken;
			model.ActivityId = activityId;//直播id
			model.ActivityIds.Add(activityId);
			model.AppName = "Seller";
			model.AutoLongSale = "false";
			model.Brand = "{\"BrandName\" : \"Kool n Soothe\",\"BrandId\" : 15147}";
			model.Category = "{\"CategoryId\" : 1123,\"SecondCategoryId\" : 1120,\"SecondCategoryName\" : \"女性护理\",\"FirstCategoryId\" : 1086,\"FirstCategoryName\" : \"美容个护\",\"CategoryName\" : \"洗液\"}";
			model.ClientId = "43a7b60d2fbcb729ed73d1534972d747";
			model.ClientType = 1;
			model.ClientUserId = long.Parse(userId);
			model.DelType = 2;
			model.DescriptionModelPicList.Add("http://pc1.img.ymatou.com/G01/shangou/M00/2A/2E/rBBlD1esTYiAV_-NAAG7XwwOBLI032_n_w_o.jpg");//图文详情图片
			model.DescriptionModelText.Add("图文详情文字");//图文详情文字
			model.DeviceToken = "623ee5d7e41fd73213df948b9cafa924d4dedc32375a06af7c02eb37c03d5893";
			model.FreeShipping = "true";
			model.Guid = "5F58DCEF-D449-46FF-81EF-02B569B9B260";
			model.IsDefault = "false";
			model.IsTop = 0;//是否置顶
			model.LimitedNumber = 0;//限购数量
			model.LocalReturn = 2;//本土退货方式
			model.NewCustomerPrice = "";//新客价
			model.NoReasonReturn = "false";//7天无理由退货
			model.NoticeRisk = "false";
			model.OnShelfNow = "false";
			model.PostAction = 3;
			model.Price = 30;//商品价格
			model.ProductDesc = "很喜欢的回到家";//商品描述
			model.ProductNumber = 0;
			model.ProductPics.Add("http://pc1.img.ymatou.com/G01/shangou/M00/2A/2E/rBBlD1esTYiAV_-NAAG7XwwOBLI032_n_w_o.jpg");//商品图片
			model.ProductSku = "{}";
			model.SaleAtNow = -1;
			model.SaleTime = "";
			model.StockNum = 1300;//商品数量
			model.TariffType = 0;//包邮包税
			model.Title = "商品标题";//商品标题
			model.VipPrice = "";
			model.UserId = long.Parse(userId);
			model.UserPosition = "中国上海市闸北区大宁路街道共和新路2596号";
			model.App = "seller";
			model.Os = "iPhone8,4";;
			model.Sys = "9.3.2";
			model.Version = "3.0.0";
			model.Wifi = 0;
				
			string val = request.post(url, model.toString(), System.Text.Encoding.GetEncoding("utf-8"));
			var responseModel = (AddProductResponseModel) JsonConvert.DeserializeObject(val, typeof(AddProductResponseModel));
			
			if (responseModel.Status != 200)
			{
				return responseModel.Msg;
			}
			else
				return "创建商品成功，商品编号为：" + responseModel.Result.ProductId;
		}
	}
}
